<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<div class="row">
    <div class="col-lg-12 col-sm-12 col-xs-12">
        <div class="widget">
            <div class="widget-header bordered-bottom theme">
                <span class="widget-caption">接口文档-${(editModel=='add')?string('新增','编辑')}</span>
                <div class="widget-buttons">
                    <a href="#" data-toggle="collapse">
                        <i class="fa fa-minus"></i>
                    </a>
                    <a href="#" data-toggle="maximize">
                        <i class="fa fa-expand"></i>
                    </a>
                </div>
            </div>
            <div class="widget-body">
                <div class="row">
                    <form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form" id="editForm_${serializeNum}"
                          data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
                          data-bv-message="This value is not valid"
                          data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                          data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                          data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
                        <input type="hidden" name="formKey" value="${formKey}">
                        <input type="hidden" name="formToken" value="${formToken}">
                        <input type="hidden" name="id" value="${editEntity.id}">
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="name" class="col-sm-2 control-label no-padding-right">所属分组</label>
                                    <div class="col-sm-10">
                                        <select required="required" data-bv-message="请选择所属分组" name="groupId" class="selectpicker_${serializeNum}" data-live-search="true">
                                            <optgroup label="请选择分组">
                                                <#list groupId_datasources as data>
                                                    <option value="${data.id}">${data.name}</option>
                                                </#list>
                                            </optgroup>
                                        </select>
                                        <script type="text/javascript">
                                            $("[name='groupId']").val("${editEntity.groupId}");
                                        </script>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="name" class="col-sm-2 control-label no-padding-right">接口名称</label>
                                    <div class="col-sm-10">
                                        <input data-bv-message="请输入接口名称" required="required" maxlength="100" name="name" alt="接口名称" id="name" placeholder="接口名称" type="text" title="接口名称" class="form-control" value="${editEntity.name}"/>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (false && editModel=='add')||(false && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="createTime" class="col-sm-2 control-label no-padding-right">创建时间</label>
                                    <div class="col-sm-10">
										<span class="input-icon icon-left">
											<input data-bv-date-format="YYYY-MM-DD hh:mm:ss" data-bv-message="The field is not valid" data-bv-date-message="请正确输入一个时间" data-bv-date="true" maxlength="19" name="createTime" alt="创建时间" id="createTime" placeholder="创建时间" type="text" title="创建时间" class="form-control form-control date-picker" onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})" value="${editEntity.createTime}"/>
											<i class="fa fa-calendar"></i>
										</span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (false && editModel=='add')||(false && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="createUserId" class="col-sm-2 control-label no-padding-right">创建人Id</label>
                                    <div class="col-sm-10">
                                        <input data-bv-message="The field is not valid" maxlength="32" name="createUserId" alt="创建人Id" id="createUserId" placeholder="创建人Id" type="text" title="创建人Id" class="form-control" value="${editEntity.createUserId}"/>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (false && editModel=='add')||(false && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="lastUpdateUserId" class="col-sm-2 control-label no-padding-right">最后一次修改人Id</label>
                                    <div class="col-sm-10">
                                        <input data-bv-message="The field is not valid" maxlength="32" name="lastUpdateUserId" alt="最后一次修改人Id" id="lastUpdateUserId" placeholder="最后一次修改人Id" type="text" title="最后一次修改人Id" class="form-control" value="${editEntity.lastUpdateUserId}"/>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="uri" class="col-sm-2 control-label no-padding-right">接口地址</label>
                                    <div class="col-sm-10">
                                        <input data-bv-message="请输入接口地址" required="required" maxlength="500" name="uri" alt="接口地址" id="uri" placeholder="接口地址" type="text" title="接口地址" class="form-control" value="${editEntity.uri}"/>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
	                    <#if (true && editModel=='add')||(true && editModel=='edit')>
	                        <div class="col-xm-12 col-sm-6 col-lg-4">
	                            <div class="form-group">
	                                <label for="weight" class="col-sm-2 control-label no-padding-right">请求方式</label>
	                                <div class="col-sm-10">
										<select required="required" data-bv-message="请选择所属分组" name="method" class="selectpicker_${serializeNum}" data-live-search="true">
	                                        <optgroup label="请选择分组">
	                                           <@dictionary groupCode="requestMethod";dics>
													<#list dics as dic>
														<option value="${dic.code}">${dic.value}</option>
													</#list>
												</@dictionary>
	                                        </optgroup>
	                                    </select>
	                                    <script type="text/javascript">
	                                        $("[name='method']").val("${editEntity.method}");
	                                    </script>
	                                </div>
	                            </div>
	                        </div>
	                    </#if>
	                    <#if (true && editModel=='add')||(true && editModel=='edit')>
	                        <div class="col-xm-12 col-sm-6 col-lg-4">
	                            <div class="form-group">
	                                <label for="weight" class="col-sm-2 control-label no-padding-right">权重</label>
	                                <div class="col-sm-10">
	                                    <input data-bv-integer-message="请输入一个数字" required="required" data-bv-message="请输入权重" data-bv-integer="true" maxlength="11" name="weight" alt="权重" id="weight" placeholder="权重" type="text" title="权重" class="form-control" value="${editEntity.weight}"/>
	                                    <span class="text"></span>
	                                </div>
	                            </div>
	                        </div>
	                    </#if>
                        <#if (false && editModel=='add')||(false && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4">
                                <div class="form-group">
                                    <label for="version" class="col-sm-2 control-label no-padding-right">版本</label>
                                    <div class="col-sm-10">
                                        <input data-bv-integer-message="The field is number" data-bv-message="The field is not valid" data-bv-integer="true" maxlength="11" name="version" alt="版本" id="version" placeholder="版本" type="text" title="版本" class="form-control" value="${editEntity.version}"/>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-6 col-lg-4" style="margin-top:30px;margin-bottom:30px; clear:left;">
                                <input type="hidden" name="cover" value="${editEntity.cover}">
                                <input type="hidden" name="deleteCover">
                                <div class="form-group">
                                    <label for="cover${serializeNum}" class="col-sm-2 control-label no-padding-right">设计图</label>
                                    <div class="col-sm-10">
                                        <div class="col-xs-9">
                                            <input data-bv-message="The field is not valid" maxlength="100" name="newCover" id="cover${serializeNum}" readonly="readonly" alt="封面图" id="headPortrait" placeholder="封面图" type="text" title="头像" class="form-control"/>
                                            <span class="text"></span>
                                        </div>
                                        <div class="col-sm-2">
                                            <a href="javascript:void(0);" class="btn theme" onclick="uploadCover('editForm_${serializeNum}','newCover','cover','cover_imgPrev${serializeNum}','cover')"><i class="fa fa-upload"></i>上传</a>
                                        </div>
                                        <div class="col-sm-12 imgPrev" id="cover_imgPrev${serializeNum}">
                                            <@file fileIds=editEntity.cover separator=',' ;files>
                                                <#list files as file>
                                                    <p>
                                                        <img src="${pv.fileRedPath}/${file.relativePath}/${file.fileName}" width="50" height="50">
                                                        ${file.fileName}
                                                        <#if file.size??>&nbsp;&nbsp;尺寸:${file.size}</#if>
                                                        <a class="btn btn-default btn-xs icon-only red delete textAling-right" href="javascript:void(0);" onclick="removeFileUseLog(this,'editForm_${serializeNum}','deleteCover','cover','${file.id}')"><i class="fa fa-trash-o"></i></a>
                                                    </p>
                                                </#list>
                                            </@file>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <script type="text/javascript">
                            function uploadCover(formId, targetShowInputName, targetHideInputName, imgPrevId, groupName) {
                                showUploadFileDialog({
                                    groupName: groupName,
                                    size: "large",//文件上传组件层大小，small 小,large 大
                                    title: "文件上传",//文件上传组件层标题
                                    width: "",//文件上传组件层宽度
                                    height: "",//文件上传组件层高度
                                    fileNumLimit: 300,//验证文件总数量, 超出则不允许加入队列
                                    fileSizeLimit: "209715200",// 验证文件总大小是否超出限制, 超出则不允许加入队列
                                    fileSingleSizeLimit: "52428800",//该参数将参与文件缓存时的唯一标识值,如果配置了文件服务器,该参数同时会参与文件服务器文件存储目录分配,为保证文件不丢失, 务必保证同一编辑页面此参数唯一
                                    accept: {
                                        title: "图片文件",//文字描述
                                        extensions: "gif,jpg,jpeg,bmp,png,psd",//允许的文件后缀，不带点，多个用逗号分割
                                        mimeTypes: "image/jpg,image/jpeg,image/png,image/gif,image/bmp,image/psd"// 多个用逗号分割
                                    },
                                    imgMaxWidth: "-1",//图片文件允许的最大宽度
                                    imgMaxHeight: "-1",// 图片文件允许的最大高度
                                    sizes: '',//缩放尺寸(格式：宽度-高度,宽度-高度,宽度-高度....),如：500-300,400-300
                                }, function (result) {//点击确认的回调函数
                                    if (result) {
                                        console.log(result.fileList);
                                        var showWidth = 50, showHeight = 50;
                                        var fileList = result.fileList;
                                        $("#" + imgPrevId).append("<hr>");
                                        for (var i = 0, len = fileList.length; i < len; i++) {
                                            var file = fileList[i];
                                            var width = file.size.width;
                                            var height = file.size.height;
                                            var uuid = file.uuid;
                                            var targetInput = $("#" + formId + " [name='" + targetShowInputName + "']").val(groupName + "=>" + targetHideInputName);
                                            if (width == -1 && height == -1) {
                                                $("#" + imgPrevId).append('<p><img  class="imgViewer"  src="fileUpload/previewUploadImg.do?groupName=' + groupName + '&fileId=' + uuid + '" width="' + showWidth + '" height="' + showHeight + '">' + file.name + '<a class="btn btn-default btn-xs icon-only red delete" href="javascript:void(0);" onclick="removeCoverUploadTempleFile(this,' + "'" + groupName + "','" + uuid + "'" + ')"><i class="fa fa-trash-o"></i></a></p>');
                                            }
                                        }
                                    }
                                }, function () {//点击取消的回调函数
                                    console.log("执行关闭/取消的回调函数");
                                })
                            }
                            //移除临时文件
                            function removeCoverUploadTempleFile(that, groupName, uuid) {
                                console.log("clear temp file  by  id...")
                                ajaxRequest("fileUpload/clearTempFile.do", {groupName: groupName, fileId: uuid}, function (result) {
                                        if (result.resCode == "200") {
                                            console.log("成功清除缓存文件：" + uuid);
                                            $(that).parents("p").remove();
                                        } else {
                                            var message = result.resMsg;
                                            bootbox.alert({
                                                title: "错误提示",
                                                size: 'small',
                                                message: message
                                            });
                                        }
                                    },
                                    function (XMLHttpRequest, textStatus, errorThrown) {
                                        ajaxError(errorThrown);
                                    }, "GET", "JSON")
                            }
                        </script>
                   		</#if>
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-12 col-lg-12">
                                <div class="form-group">
                                    <label for="requestExample" class="col-sm-1 control-label no-padding-right">请求举例</label>
                                    <div class="col-sm-11">
                                        <textarea data-bv-message="请输请求举例" rows="10" style="resize: none;" required="required" maxlength="500" name="requestExample" alt="请求举例" id="requestExample" placeholder="请求举例" type="text" title="请求举例" class="form-control">${editEntity.requestExample}</textarea>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-12 col-lg-12">
                                <div class="form-group">
                                    <label for="responseExample" class="col-sm-1 control-label no-padding-right">响应举例</label>
                                    <div class="col-sm-11">
                                        <textarea data-bv-message="响应举例" rows="10" style="resize: none;" required="required" maxlength="21845" name="responseExample" alt="响应举例" id="responseExample" placeholder="响应举例" type="text" title="响应举例" class="form-control">${editEntity.responseExample}</textarea>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                        <#if (true && editModel=='add')||(true && editModel=='edit')>
                            <div class="col-xm-12 col-sm-12 col-lg-12">
                                <div class="form-group">
                                    <label for="remark" class="col-sm-1 control-label no-padding-right">备注</label>
                                    <div class="col-sm-11">
                                        <textarea rows="10" style="resize: none;" name="remark" alt="备注" id="remark" maxlength="255" placeholder="备注" type="text" title="备注" class="form-control">${editEntity.remark}</textarea>
                                        <span class="text"></span>
                                    </div>
                                </div>
                            </div>
                        </#if>
                    <div class="col-sm-12">
                        <input type="button" class="btn btn-default" data-dismiss="modal" value="返回" onclick="backView()"/>
                        <button type="submit" class="btn btn-blue" id="editFormSubmitBtn_${serializeNum}">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
    $(".selectpicker_${serializeNum}").select2();
    function removeFileUseLog(that, formId, targetDeleteInputName, targetHideInputName, fileId) {
        var useFileIds = $("#" + formId + " [name='" + targetHideInputName + "']");
        var targetDeleteInput = $("#" + formId + " [name='" + targetDeleteInputName + "']");
        var ids = useFileIds.val().split(",");
        var newIds = "";
        for (var i = 0, len = ids.length; i < len; i++) {
            if (ids[i] == fileId) {
                targetDeleteInput.val(targetDeleteInput.val() + "," + fileId);
                continue;
            }
            newIds += ids[i];
            if (i != len - 1) {
                newIds += ",";
            }
        }
        useFileIds.val(newIds);
        $(that).parents("p").remove();
    }
</script>